<?php

namespace app\controller;


use app\common\lib\Aes;
use app\common\lib\Common;
use bootstrap\DBListen;
use Webman\Event\Event;

abstract class CoreController
{

    public function __construct()
    {
    }

    /**
     * 特别说明：如果传了msg 参数，说明需要成功提示，否则不要传
     * @param array $data
     * @param string $msg
     * @return \Illuminate\Http\JsonResponse
     */
    protected function endSuccess($data = [], $msg = 'ok')
    {
        //返回结果加密处理
        $pathInfo = trim(request()->path(),'/');
        $pathInfos = explode('/',$pathInfo);
        $platform = strtoupper(request()->platform);
        request()->reponseResult = $data;

        if(in_array($pathInfos[0],['index']) && (boolean)config('env.AES_'.$platform.'_ENCRYPT',true)){
            $data  = Aes::getInstance()->encode($data);
        }


        return Common::endJson(0, $msg, $data);
    }
}
